package com.ruoyi.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @Program: animalSystem->CorsConfig
 * @Description: 后端解决跨越问题
 * @Author: donghang
 * @Date: 2023-03-21 17:25
 * @Version： 1.0
 **/
//@Configuration
public class CorsConfig {

    @Bean
    public CorsWebFilter corsWebFilter(){
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowCredentials(true);//是否允许携带cookie
        configuration.addAllowedOrigin("http://localhost");//可接妥的城。是一个具体域名或音*（代农任感域名)
        configuration.addAllowedHeader("*");//元许携劳的头
        configuration.addAllowedMethod("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**",configuration);

        return new CorsWebFilter (source);
    }
}
